package com.ag.admin.web.tags;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.ag.admin.service.IAuthorizeService;
import com.ag.admin.utils.UserUtil;

public class ViceCommanderTag extends TagSupport implements
		ApplicationContextAware {
	private static final long serialVersionUID = -5082619765870671777L;

	private static ApplicationContext context;// 声明一个静态变量保存

	private IAuthorizeService authorizeService;

	private String permission;

	@Override
	public int doStartTag() throws JspException {
		authorizeService = (IAuthorizeService) context
				.getBean("AuthorizeServiceImpl");
		HttpSession session = pageContext.getSession();
		if (authorizeService.checkRole(session, UserUtil.VICE_COMMANDER)) {
			return EVAL_BODY_INCLUDE;
		}
		return SKIP_BODY;
	}

	@Override
	public void setApplicationContext(ApplicationContext contex)
			throws BeansException {
		this.context = contex;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public static ApplicationContext getContext() {
		return context;
	}
}
